package xyz.o0o0o.demo.mybatis;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.log4j.Logger;

/**
 * Hello world!
 *
 */
public class App {

    private final Logger log = Logger.getLogger(App.class);

    public static void main(String[] args) throws IOException {
        String route = "/*!mycat: schema = TESTDB */";
        String route1 = "/*!mycat: schema = TESTDB1*/";

        int id = 1;
        int id2 = 3333333;

        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sqlSessionFactory.openSession();

        try {
            Map params = new HashMap();
            params.put("route", route);
            params.put("id", id);
            Goods goods = (Goods) session.selectOne("GoodsMapper.selectGood", params);
            System.out.println(goods.getId() + ":" + goods.getName());
        } finally {
            session.close();
        }
    }
}
